package com.bicon.botu.account;

import com.bicon.botu.core.base.annotation.*;
import com.bicon.botu.core.base.bean.GlobalRedisTemplate;
import com.bicon.botu.core.base.config.SystemInterceptor;
import com.bicon.botu.core.base.repository.redis.RedisTemplateUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 用户注册登录控制器
 */
@SpringBootApplication
@EnableGlobalRedis
@EnableMyBatisPlusConfig // MyBatis配置
@MapperScan("com.bicon.botu.account.mapper") //扫描mapper
@ComponentScan(basePackages = "com.bicon.botu.*.service")
@ComponentScan(basePackages = "com.bicon.botu.*.handler")
@ComponentScan(basePackages = "com.bicon.botu.*.provider")
@RestController
@EnableHttpLogAspect //http请求日志
@EnableGlobalExceptionHandler //统一异常处理
@EnableSystemInterceptor //系统拦截器
public class AccountApplication extends WebMvcConfigurerAdapter {
    public static void main(String[] args) {
        SpringApplication.run(AccountApplication.class, args);
    }

    @Bean
    public SystemInterceptor getMyInterceptor(){
        return new SystemInterceptor();
    }

    /**
     * 配置拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getMyInterceptor()).addPathPatterns("/**");
    }

    @Autowired
    private GlobalRedisTemplate globalRedisTemplate;

    @Bean
    RedisTemplateUtil redisTemplateUtil(){
        return new RedisTemplateUtil(globalRedisTemplate);
    }
}
